#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <string>

using namespace std;

int main(int argc, char const *argv[])
{
    vector<string> results;
    vector<int> vec;
    map<int, vector<int> > temps;
    set<int> a, b;
    char c;
    int t, n, m, x, y, l, r;
    int i, j, k, depth, temp;
    
    cin >> t;
    for (i = 0; i < t; i++)
    {
        cin >> n >> m;
        a = set<int>();
        b = set<int>();
        temps = map<int, vector<int> >();
        for (i = 0; i < n; i++)
        {
            temps.insert(make_pair(i, vector<int>()));
        }
        
        for (j = 0; j < m; j++)
        {
            cin >> c >> x >> y;
            
            if (c == 'Q')
            {
                if (x == y) 
                {
                    results.push_back("In the same gang.");
                    continue;
                }

                if (a.find(x) != a.end()) l = 0;
                else if (b.find(x) != b.end()) l = 1;
                else l = 2;
                
                if (a.find(y) != a.end()) r = 0;
                else if (b.find(y) != b.end()) r = 1;
                else r = 2;

                
                
                if (l == 2 || r == 2) 
                {
                    if (find(temps[x].begin(), temps[x].end(), y) != temps[x].end())
                    {
                        results.push_back("In different gangs.");
                    }
                    else if (find(temps[y].begin(), temps[y].end(), x) != temps[y].end())
                    {
                        results.push_back("In different gangs.");
                    }
                    else
                    {
                        results.push_back("Not sure yet.");
                    }
                    
                } 
                else if (l == r) results.push_back("In the same gang.");
                else results.push_back("In different gangs.");
                continue;
            }

            if (a.size() == 0)
            {
                a.insert(x);
                b.insert(y);
                continue;
            }
            
            temps[x].push_back(y);
            temps[y].push_back(x);

            if (a.find(x) != a.end() || b.find(y) != b.end())
            {
                vec = temps[x];
                for (k = 0; k < vec.size(); k++)
                {
                    b.insert(vec[k]);
                }
                temps[x] = vector<int>();

                vec = temps[y];
                for (k = 0; k < vec.size(); k++)
                {
                    a.insert(vec[k]);
                }
                temps[y] = vector<int>();
            }
            else if (a.find(y) != a.end() || b.find(x) != b.end())
            {
                vec = temps[y];
                for (k = 0; k < vec.size(); k++)
                {
                    b.insert(vec[k]);
                }
                temps[y] = vector<int>();

                vec = temps[x];
                for (k = 0; k < vec.size(); k++)
                {
                    a.insert(vec[k]);
                }
                temps[x] = vector<int>();
            }
        }
    }

    for (i = 0; i < results.size(); i++)
    {
        if (i)
        {
            cout << "\n";
        }
        cout << results[i];        
    }
    
    
    return 0;
}
